<?php

namespace addons\qingdongams\model;

use think\Model;
use traits\model\SoftDelete;

/**
 *联系人表
 */
class ContractFile Extends Model {
	use SoftDelete;
    // 表名,不含前缀
    protected $name = 'qingdongams_contract_file';
	// 开启自动写入时间戳字段
	protected $autoWriteTimestamp = 'int';
	// 定义时间戳字段名
	protected $createTime = false;
	protected $updateTime = false;
	protected $deleteTime = false;

	//附件表
	public function file() {
		return $this->hasOne(File::class, 'id', 'file_id')->with('staff')->bind('id,size,create_staff_id,types,name,file_path,staff');
	}

	public static function addFiles($files, $customer_id) {
		$files    = explode(',', $files);
		$addFiles = [];
		foreach ($files as $v) {
			$addFiles[] = [
				'contract_id' => $customer_id,
				'file_id'     => $v
			];
		}
		$model=new self();
		if($model->insertAll($addFiles)){
			return true;
		}
		return false;
	}
}
